<?php

//MyOC

// Version
define('VERSION', '1.5.2.1');

// Configuration
require_once('config.php');
 
// Install
if (!defined('DIR_APPLICATION')) {
  header('Location: install/index.php');
  exit;
}

// Startup
require_once(DIR_SYSTEM . 'startup.php');

// Application Classes
require_once(DIR_SYSTEM . 'library/customer.php');
require_once(DIR_SYSTEM . 'library/affiliate.php');
require_once(DIR_SYSTEM . 'library/currency.php');
require_once(DIR_SYSTEM . 'library/tax.php');
require_once(DIR_SYSTEM . 'library/weight.php');
require_once(DIR_SYSTEM . 'library/length.php');
require_once(DIR_SYSTEM . 'library/cart.php');

// Registry
$registry = new Registry();

// Loader
$loader = new Loader($registry);
$registry->set('load', $loader);

// Config
$config = new Config();
$registry->set('config', $config);

// Database
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$registry->set('db', $db);

// Request
$request = new Request();
$registry->set('request', $request);

/***************************************************************************/
 
define('username',      'test');
define('password',  'password');

$success = '';
$error_warning = '';

if ($request->server['REQUEST_METHOD'] == 'POST') {

  if ( isset($request->post['username']) &&
       isset($request->post['password']) &&
       isset($request->post['date']) &&
       isset($request->post['task']) &&
       isset($request->post['security'])
      ) 
  {
    if ( $request->post['username'] == username &&
         $request->post['password'] == password && 
         $request->post['security'] == md5( DB_PASSWORD ) &&
         $request->post['task'] == 'setdate') {

      $data = $request->post['date'];     
           
      $data_split = array(); 
      $data_split = preg_split( '/[-\.\/ ]/', $data );
    
      if ( count( $data_split ) != 3 ) {
        $error_warning = 'data ricevuta in input = '. $data .' non valida. Il formato corretto e\' dd/mm/yyyy oppure dd-mm-yyyy';
      } 
      else 
      {
        if ( !checkdate( $data_split[1], $data_split[0], $data_split[2] ) ) {
          $error_warning = 'data ricevuta in input = '. $data .' non valida. Il formato corretto e\' dd/mm/yyyy oppure dd-mm-yyyy';
        } else {
          // procedo all'inserimento sulla site_date
          $success = 'Data aggiornata con il valore : '. $data;
          $data = $db->escape($data_split[2] .'-'.$data_split[1].'-'.$data_split[0]);
          $db->query("UPDATE site_date set site_date = '$data'");
        }
      }
    }
    else
    {
      $error_warning = 'Accesso negato';
    }
  }
  else
  {
    $error_warning = 'Accesso negato';
  }
}

// leggo la data
$queryStr = "SELECT DATE_FORMAT(site_date, '%d/%m/%Y') as data FROM   site_date";
$query = $db->query($queryStr);
$data = $query->row['data'];

$security = md5( DB_PASSWORD );

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  dir="ltr" lang="it"
  xml:lang="it">
<head>
<title>Imposta data riferimento</title>
<link rel="stylesheet" type="text/css"
  href="admin/view/stylesheet/stylesheet.css" />
<script type="text/javascript"
  src="admin/view/javascript/jquery/jquery-1.7.1.min.js"></script>
<script type="text/javascript"
  src="admin/view/javascript/jquery/ui/jquery-ui-1.8.16.custom.min.js"></script>
<link rel="stylesheet" type="text/css"
  href="admin/view/javascript/jquery/ui/themes/ui-lightness/jquery-ui-1.8.16.custom.css" />
<script type="text/javascript"
  src="admin/view/javascript/jquery/ui/external/jquery.bgiframe-2.1.2.js"></script>
<script type="text/javascript" src="admin/view/javascript/jquery/tabs.js"></script>

<script type="text/javascript"
  src="admin/view/javascript/jquery/superfish/js/superfish.js"></script>

</head>
<body>
<div id="container">
<div id="header">
<div class="div1">
<div class="div2"><img src="view/image/logo.png"
  title="Amministrazione"/></div>
</div>
</div><div id="content">
<div class="box"
  style="width: 400px; min-height: 300px; margin-top: 40px; margin-left: auto; margin-right: auto;">
<div class="heading">
<h1><img src="admin/view/image/lockscreen.png" alt="" /> Cambia la data di riferimento.</h1>

</div>
<div class="content" style="min-height: 150px; overflow: hidden;">

<?php if ($success) { ?>
<div class="success"><?php echo $success; ?></div>
<?php } ?>
<?php if ($error_warning) { ?>
<div class="warning"><?php echo $error_warning; ?></div>
<?php } ?>

<form action="setdate.php" method="post"
  enctype="multipart/form-data" id="form">
<table style="width: 100%;">
  <tr>
    <td style="text-align: center;" rowspan="4"><img
      src="admin/view/image/login.png" alt="." /></td>
  </tr>
  <tr>
    <td>Username:<br />

    <input type="text" name="username" value=""
      style="margin-top: 4px;" /> <br />
    <br />
    Password:<br />
    <input type="password" name="password"
      value="" style="margin-top: 4px;" /> <br />
   <br />
    Data:<br />
       <input type="text" name="date" 
         value="<?php echo $data; ?>" style="margin-top: 4px;" >
       <br />
    </td>
  </tr>
  <tr>

    <td>&nbsp;</td>
  </tr>
  <tr>
    <td style="text-align: right;"><a onclick="$('#form').submit();"
      class="button">Imposta</a></td>
  </tr>
</table>
  <input type="hidden" name="task" value="setdate">
  <input type="hidden" name="security" value="<?php echo $security;?>">

    </form>
</div>
</div>
</div>

<script type="text/javascript"><!--
$('#form input').keydown(function(e) {
  if (e.keyCode == 13) {
    $('#form').submit();
  }
});
//--></script>
    </div>
<div id="footer"><a href="index_test.php">Vai al sito di test</a></div>
<div class="column"></div>

</body>
</html>
